import Vue from 'vue'
// import './transition/transition.css'

Vue.mixin({
	data(){
		return {
			UI:{
				loading:{
					show:false,
					text:'',
					filter:false,
					timeout:null
				},
				toast:{
					show:false,
					text:'',
					icon:'',
					bottom:false,
					timeout:null
				},
				alert:{
					show:false,
					text:'',
					callback1:null,
					callback2:null,
					btn:''
				},
				qrcode:{
          show:false
				}
			}
		}
	}
})

Vue.prototype.showLoading=function(text='正在加载',filter=false){
  let that=this;
	let loading=this.$root.UI.loading;
	loading.show=true;
	loading.text=text;
	loading.filter=filter;
	clearTimeout(loading.timeout);
	loading.timeout=setTimeout(function(){
    if(loading.show==true){
      that.hideLoading();
      that.showToast(' 网络不给力哦~ ','');
    }
	},20000)
}
Vue.prototype.hideLoading=function(){
	let loading=this.$root.UI.loading;
	loading.show=false;
}
Vue.prototype.showToast=function(text='成功',icon='success',bottom=false){
	let that=this;
	let toast=this.$root.UI.toast;
	toast.show=true;
	toast.text=text;
	toast.icon=icon;
	toast.bottom=bottom;
	clearTimeout(toast.timeout);
	toast.timeout=setTimeout(function(){
		that.hideToast();
	},1500)
}
Vue.prototype.hideToast=function(){
	let toast=this.$root.UI.toast;
	toast.show=false;
}
Vue.prototype.showAlert=function(text='提示',callback1=function(){},callback2=null,btn='确定'){
  let alert=this.$root.UI.alert;
  alert.show=true;
  alert.text=text;
  alert.callback1=callback1;
  alert.callback2=callback2;
  alert.btn=btn;
}
Vue.prototype.hideAlert=function(){
	let alert=this.$root.UI.alert;
	alert.show=false;
}
Vue.prototype.showQrcode=function(){
  let qrcode=this.$root.UI.qrcode;
  qrcode.show=true;
}
Vue.prototype.hideQrcode=function(){
  let qrcode=this.$root.UI.qrcode;
  qrcode.show=false;
}
